package com.talent.jiwen.chatlive;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import com.abc.live.ui.live.ABCInteractiveActivity;
import com.abcpen.open.api.model.ABCUserMo;
import com.abcpen.open.api.model.RoomMo;
import com.liveaa.livemeeting.sdk.biz.core.ABCLiveSDK;
import com.talent.jiwen.ActivityManager;
import com.talent.jiwen.LoginActivity;
import com.talent.jiwen.R;
import com.talent.jiwen.my.PayActivity;
import com.talent.jiwen.util.ImageUtil;
import com.talent.jiwen.util.SPUtil;
import com.wevey.selector.dialog.MDSelectionDialog;

import java.util.ArrayList;
import java.util.List;

import cn.jpush.android.api.JPushInterface;
import me.jessyan.autosize.internal.CancelAdapt;

/**
 * Created by zhaocheng on 2017/6/28.
 */

public class InteractiveActivity extends ABCInteractiveActivity implements CancelAdapt {

    private boolean isRecording = false;
    private MDSelectionDialog exitDialog;
    ArrayList exitDialogData = new ArrayList<>();

    public static final String TIME_FINISH_CLASS = "time.finish.class";

    private String roomId;
    @Override
    public void onShareViewClick(RoomMo mo) {
        // TODO: 2017/6/28 share
    }

//    @Subscribe
//    public void onEvent(String flag){//免单课程结束通知
//        if (flag.equals(TIME_FINISH_CLASS)){
//            destroyData();
//            Toast.makeText(this, "体验课程已结束", Toast.LENGTH_SHORT).show();
//            PayActivity.startPayActivity(InteractiveActivity.this , roomId);
//        }
//    }


    @Override
    public void upLoadImgAndSendMsg(final String filePath, final int width, final int height, final int pageNo, final String wbId) {
        ImageUtil.upLoadSingleImg(filePath, new ImageUtil.ImgUpLoadListener() {
            @Override
            public void OnSuccess(String successUrl) {
                /**
                 * 发送消息
                 */
                if (mWhiteboardFragment != null) {
                    mWhiteboardFragment.sendPhotoImageForUrl(successUrl, filePath, width, height, pageNo, wbId);
                }
            }

            @Override
            public void OnError(String message) {

            }

            @Override
            public void OnListUpSuccess(List<String> successFileList) {

            }
        });
    }

    @Override
    public void onRemoteDoCloseLive() {
        Log.d("zc", "onRemoteDoCloseLive: ");
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        EventBus.getDefault().register(this);
        exitDialogData.add(getString(R.string.abc_temp_leave));
        exitDialogData.add(getString(R.string.abc_leave_class));
        exitDialogData.add(getString(R.string.abc_common_cancel));
        roomId=mRoomMo.room_id;
    }

    @Override
    protected void onMeetingFinish() {
        Toast.makeText(this, "课程已结束", Toast.LENGTH_SHORT).show();
        PayActivity.startPayActivity(InteractiveActivity.this , roomId);

    }

    /**
     * 透传消息
     *
     * @param uid
     * @param data
     */
    @Override
    public void onCMDMsg(ABCUserMo uid, String data) {
        ABCLiveSDK.showToast("name" + uid.uname + " data" + data);
    }

    /**
     * 指定透传消息
     *
     * @param uid
     * @param tuid
     * @param data
     */
    @Override
    public void onCMDToUserMsg(ABCUserMo uid, ABCUserMo tuid, String data) {
        ABCLiveSDK.showToast("name" + uid.uname + " data" + data);
    }

    @Override
    public void setFinishLoading() {

    }




    /**
     * 踢出用户
     *
     * @param fid
     * @param userId
     * @param kickedUser
     */
    @Override
    public void onKickedOutUser(String fid, String userId, int kickedUser) {

    }

    /**
     * 获取用户信息
     *
     * @param what
     * @param userMos
     */
    @Override
    public void onUsersInfo(int what, List<ABCUserMo> userMos) {

    }

    /**
     * token 验证失败
     */
    @Override
    public void onErrorOpen() {
        super.onErrorOpen();
        Toast.makeText(InteractiveActivity.this,"token验证失败，请重新登录",Toast.LENGTH_SHORT).show();
        SPUtil.clearAll();
        ActivityManager.getAppManager().finishAllActivity();
        startActivity(new Intent(InteractiveActivity.this,LoginActivity.class));
        JPushInterface.setAlias(InteractiveActivity.this , (int)Math.random(), "");
        finish();
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
//        EventBus.getDefault().unregister(this);
    }
}
